extends Node2D

var character: Variant

var _combo_time: float

var _combo_count: int

@onready var animator: AnimatedSprite2D = %Animator


class AnimationEnterStateComponent extends StateComponent:
	var _animator: AnimatedSprite2D
	
	func _init(init_name: String, init_animator: AnimatedSprite2D) -> void:
		super(init_name)
		_animator = init_animator
	
	func _on_enter() -> void:
		_animator.visible = true


class AnimationExitStateComponent extends StateComponent:
	var _animator: AnimatedSprite2D
	
	func _init(init_name: String, init_animator: AnimatedSprite2D) -> void:
		super(init_name)
		_animator = init_animator
	
	func _on_exit() -> void:
		_animator.visible = false


func _init() -> void:
	character = null
	_combo_time = 2.0
	_combo_count = 2


func on_attach() -> void:
	var basic_attack_state = character.state_machine.get_state("ground.basic_attack")
	basic_attack_state.add_component(ComboAnimationStateComponent.new("player_sword_combo_animation", character.animator, "sword_basic_attack", _combo_count, _combo_time))
	basic_attack_state.add_component(ComboAnimationStateComponent.new("sword_combo_animation", animator, "basic_attack", _combo_count, _combo_time))
	basic_attack_state.add_component(AnimationEnterStateComponent.new("sword_animation_enter", animator))
	basic_attack_state.add_component(AnimationExitStateComponent.new("sword_animation_exit", animator))


func on_update(_delta: float) -> void:
	pass


func on_detach() -> void:
	var basic_attack_state = character.state_machine.get_state("ground.basic_attack")
	basic_attack_state.remove_component("sword_animation_exit")
	basic_attack_state.remove_component("sword_animation_enter")
	basic_attack_state.remove_component("sword_combo_animation")
	basic_attack_state.remove_component("player_sword_combo_animation")
